package com.citsin.atlas.viewmodel

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
import com.citsin.atlas.bean.Media

/**
 * citsin
 * 2019-06-03
 */
class MediaViewModel(
    application: Application,  private val mediaTypes: Array<Int>,
    private val bucketId: String
) : AndroidViewModel(application) {

    private val mediaList: LiveData<PagedList<Media>>

    init {
        val config = PagedList.Config.Builder()
            .setPageSize(20)
            .setEnablePlaceholders(false)
            .build()
        mediaList = LivePagedListBuilder<Int, Media>(
            MediaDataSourceFactory(application, mediaTypes, bucketId), config
        ).build()
    }

    fun getMedia():LiveData<PagedList<Media>>{
        return mediaList
    }

}
